<?php 
class Model_Setting extends CI_Model
{
	function getSetting($group, $store_id = 0) {
		$data = array(); 
		$query = $this->db->query("SELECT * FROM " . $this->db->dbprefix . "setting WHERE store_id = '" . (int)$store_id . "' AND `group` = " . $this->db->escape($group) . "");
		
		foreach ($query->result_array() as $result) {
			$data[$result['key']] = $result['value'];
		}
		
		

		return $data;
	}
	
	function editSetting($group, $data, $store_id = 0) {
		$this->db->trans_start();
		$this->db->query("DELETE FROM " .  $this->db->dbprefix  . "setting WHERE store_id = '" . (int)$store_id . "' AND `group` = " . $this->db->escape($group) . "");

		foreach ($data as $key => $value) {
			if (!is_array($value)) {
				$this->db->query("INSERT INTO " .  $this->db->dbprefix  . "setting SET store_id = '" . (int)$store_id . "', `group` = " . $this->db->escape($group) . ", `key` = " . $this->db->escape($key) . ", `value` = " . $this->db->escape($value) . "");
			} else {
				$this->db->query("INSERT INTO " .  $this->db->dbprefix  . "setting SET store_id = '" . (int)$store_id . "', `group` = " . $this->db->escape($group) . ", `key` = " . $this->db->escape($key) . ", `value` = " . $this->db->escape(serialize($value)) . ", serialized = '1'");
			}
		}
		
		$this->db->trans_complete();
	}
	
	
	
	function deleteSetting($group, $store_id = 0) {
		$this->db->query("DELETE FROM " . $this->db->dbprefix . "setting WHERE store_id = '" . (int)$store_id . "' AND `group` = " . $this->db->escape($group) . "");
	}
}
?>